# coding=utf-8
import json

from common.campaign.model.daily_recharge import DailyRecharge
from common.utils.decorator import sql_wrapper
from common.utils.tz import today_str


@sql_wrapper
def get_status(user_id):
    item = DailyRecharge.query.filter(
        DailyRecharge.user_id == user_id).filter(
        DailyRecharge.date == today_str()).first()
    return item


@sql_wrapper
def create_campaign(user_id, price, campaign_info):
    item = DailyRecharge()
    item.user_id = user_id
    item.date = today_str()
    item.price = price
    item.campaign_id = campaign_info['campaign_id']
    item.extend = json.dumps(campaign_info, ensure_ascii=False)
    item.save()
